<?php

include dirname( __FILE__ )."/header.php";
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object

if (!empty($_POST['submit'])) {
	if (empty($xoopsUser)) {
		$sender = 0;
	} else {
		$sender = $xoopsUser->getVar('uid');
	}
	$lid = intval($_POST['lid']);
	$ip = getenv("REMOTE_ADDR");
	if ($sender != 0) {
		// Check if REG user is trying to report twice.
   		$result=$xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix($mydirname."_broken")." WHERE lid=".$lid." AND sender=".$sender."");
       	list($count)=$xoopsDB->fetchRow($result);
       	if ($count > 0) {
			redirect_header("index.php",2,_MD_MYLINKS_ALREADYREPORTED);
			exit();
        }
  	} else {
   		// Check if the sender is trying to vote more than once.
    	$result=$xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix($mydirname."_broken")." WHERE lid=$lid AND ip = '$ip'");
   		list($count)=$xoopsDB->fetchRow($result);
    	if ($count > 0) {
			redirect_header("index.php",2,_MD_MYLINKS_ALREADYREPORTED);
			exit();
    	}
	}
	$newid = $xoopsDB->genId($xoopsDB->prefix($mydirname."_broken")."_reportid_seq");
	$sql = sprintf("INSERT INTO %s (reportid, lid, sender, ip) VALUES (%u, %u, %u, '%s')", $xoopsDB->prefix($mydirname."_broken"), $newid, $lid, $sender, $ip);
	$xoopsDB->query($sql) or exit();
	$tags = array();
	$tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=listBrokenLinks';
	$notification_handler =& xoops_gethandler('notification');
	$notification_handler->triggerEvent('global', 0, 'link_broken', $tags);
	redirect_header("index.php",2,_MD_MYLINKS_THANKSFORINFO);
	exit();
} else {
	$xoopsOption['template_main'] = $mydirname.'_brokenlink.html';
	include XOOPS_ROOT_PATH.'/header.php';
//wanikoo
$mylinks_module_header = '';
$mylinks_module_header .= '
	<link rel="stylesheet" type="text/css" href="'.mylinksGetStyleURL("mylinks.css").'" />
	<script src="'.mylinksGetStyleURL("mylinks.js").'" type="text/javascript"></script>
	';
$mylinks_module_header = $mylinks_module_header; 
$xoopsTpl->assign('xoops_module_header', $mylinks_module_header);
//

	$xoopsTpl->assign('lang_reportbroken', _MD_MYLINKS_REPORTBROKEN);
	$xoopsTpl->assign('link_id', intval($_GET['lid']));
	$xoopsTpl->assign('lang_thanksforhelp', _MD_MYLINKS_THANKSFORHELP);
	$xoopsTpl->assign('lang_forsecurity', _MD_MYLINKS_FORSECURITY);
	$xoopsTpl->assign('lang_cancel', _MD_MYLINKS_CANCEL);

//wanikoo theme changer
$xoopsTpl->assign("lang_themechanger", _MD_MYLINKS_THEMECHANGER);
$mymylinkstheme_options = '';

    foreach ($GLOBALS['mylinks_allowed_theme'] as $mymylinkstheme) {
        $mymylinkstheme_options .= '<option value="'.$mymylinkstheme.'"';
        if ($mymylinkstheme == $GLOBALS['mylinks_theme']) {
            $mymylinkstheme_options .= ' selected="selected"';
        }
        $mymylinkstheme_options .= '>'.$mymylinkstheme.'</option>';
    }

    $mylinkstheme_select = '<select name="mylinks_theme_select" onchange="submit();" size="1">'.$mymylinkstheme_options.'</select>';

$xoopsTpl->assign("mylinksthemeoption", $mylinkstheme_select);

//wanikoo search
if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/search.php") ) {
   include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/search.php";
} else {
   include_once XOOPS_ROOT_PATH."/language/english/search.php";
}
$xoopsTpl->assign('lang_all', _SR_ALL);
$xoopsTpl->assign('lang_any', _SR_ANY);
$xoopsTpl->assign('lang_exact', _SR_EXACT);
$xoopsTpl->assign('lang_search', _SR_SEARCH);
$xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));
//category head
$catarray = array();
if ( $mylinks_show_letters ) {
$catarray['letters'] = ml_wfd_letters();
}
if ( $mylinks_show_toolbar ) {
$catarray['toolbar'] = ml_wfd_toolbar();
}
$xoopsTpl->assign('catarray', $catarray);

	include_once dirname( __FILE__ )."/footer.php";

}

?>